/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlysieuthi;

import DTO.CChiTietHoaDon;
import DTO.CConfig;
import DTO.CHeThong;
import java.sql.Timestamp;
import DTO.CKho;
import DTO.CTon_Kho;
import Model.CModel;
import Model.CReport;
import java.awt.event.ItemEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
public class FrmBaoCao extends javax.swing.JFrame {

    /**
     * Creates new form FrmBaoCaoLoiNhuan
     */
    public FrmBaoCao() {
        initComponents();
        
        
    }
    public FrmBaoCao(int t) {
        initComponents();
        this.loai = t;
        loadCuaHang(true);//cua hang
        Date d = new Date();
        begin = new Timestamp(d.getYear(), d.getMonth(), 1, 0, 0, 1, 0);
        end = new Timestamp(d.getYear(), d.getMonth(), 28, 23, 59, 50, 0);   
        pan_cuahangkho.setVisible(true);
        if(loai == 6 || loai == 5){
            pan_cuahangkho.setVisible(false);
            if(loai == 5){
                this.lblTitle.setText("Báo Cáo Doanh Thu Toàn Hệ Thống");
            }
            else{
                this.lblTitle.setText("Báo Cáo Lợi Nhuận Toàn Hệ Thống");
            }
        }
        else
        if(loai == 4){
            this.pan_thang.setVisible(false);
            pan_cuahangkho.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn cửa hàng"));
            loadCuaHang(true);//bao cao ton  cua hang
             this.lblTitle.setText("Báo Cáo Tồn Cửa Hàng");
        }
        else
        if(loai == 3){
            this.pan_thang.setVisible(false);
            pan_cuahangkho.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn kho hàng"));
            loadCuaHang(false);//bao cao ton kho
            this.lblTitle.setText("Báo Cáo Tồn Kho");
        }
        else{
            this.pan_thang.setVisible(true);
            pan_cuahangkho.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn cửa hàng"));
            loadCuaHang(true);
             if(loai == 1){
                this.lblTitle.setText("Báo Cáo Lợi Nhuận");
            }
            else{
                this.lblTitle.setText("Báo Cáo Doanh Thu");
            }
        }
    }
    Timestamp begin = null;
    Timestamp end = null;
    List<CKho> lcuaHang = new ArrayList<CKho>();
    private int loai = 3;//mac dinh la bao cao loi nhuan
    
    private void loadCuaHang(Boolean b){
        CModel _model = new CModel(QuanLySieuThi.user_name);
        lcuaHang = _model.getKho(b);
        _model.Close();
        this.cbbkho.removeAllItems();
        for(CKho item : lcuaHang){
            this.cbbkho.addItem(item.getTenKho());
        }
        this.cbbnam.removeAllItems();
        this.cbbnam.addItem(" -- Chọn năm ---");
        for(int i = 2014; i < 2019;i++){
            this.cbbnam.addItem("" + i);
        }
        this.cbbthang_quy.removeAllItems();
        this.cbbthang_quy.addItem(" --- Chọn tháng --- ");
        for(int i = 1;i <= 12;i++){
            this.cbbthang_quy.addItem("" + i);
        }
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnPrintf = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        lblTitle = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        pan_cuahangkho = new javax.swing.JPanel();
        cbbkho = new javax.swing.JComboBox();
        pan_thang = new javax.swing.JPanel();
        cbbloai_baocao = new javax.swing.JComboBox();
        pal1 = new javax.swing.JPanel();
        cbbthang_quy = new javax.swing.JComboBox();
        cbbnam = new javax.swing.JComboBox();

        btnPrintf.setText("Xem");
        btnPrintf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrintfActionPerformed(evt);
            }
        });

        btnClose.setText("Thoát");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        lblTitle.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblTitle.setForeground(new java.awt.Color(102, 102, 255));
        lblTitle.setText("jLabel1");

        pan_cuahangkho.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn cửa hàng"));

        cbbkho.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout pan_cuahangkhoLayout = new javax.swing.GroupLayout(pan_cuahangkho);
        pan_cuahangkho.setLayout(pan_cuahangkhoLayout);
        pan_cuahangkhoLayout.setHorizontalGroup(
            pan_cuahangkhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pan_cuahangkhoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cbbkho, 0, 153, Short.MAX_VALUE)
                .addContainerGap())
        );
        pan_cuahangkhoLayout.setVerticalGroup(
            pan_cuahangkhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pan_cuahangkhoLayout.createSequentialGroup()
                .addComponent(cbbkho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pan_thang.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn loại báo cáo"));

        cbbloai_baocao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tháng", "Quý ", "Năm" }));
        cbbloai_baocao.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbloai_baocaoItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout pan_thangLayout = new javax.swing.GroupLayout(pan_thang);
        pan_thang.setLayout(pan_thangLayout);
        pan_thangLayout.setHorizontalGroup(
            pan_thangLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pan_thangLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cbbloai_baocao, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pan_thangLayout.setVerticalGroup(
            pan_thangLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pan_thangLayout.createSequentialGroup()
                .addComponent(cbbloai_baocao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        pal1.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn"));

        cbbthang_quy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbnam.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout pal1Layout = new javax.swing.GroupLayout(pal1);
        pal1.setLayout(pal1Layout);
        pal1Layout.setHorizontalGroup(
            pal1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pal1Layout.createSequentialGroup()
                .addComponent(cbbthang_quy, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(cbbnam, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pal1Layout.setVerticalGroup(
            pal1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pal1Layout.createSequentialGroup()
                .addGroup(pal1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbbthang_quy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbnam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pan_cuahangkho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(pan_thang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pal1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pal1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(pan_cuahangkho, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pan_thang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, 22))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(lblTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(btnPrintf, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(47, 47, 47)
                            .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(14, 14, 14))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(lblTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnPrintf)
                    .addComponent(btnClose))
                .addGap(17, 17, 17))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btnCloseActionPerformed

    
   
    
    private int getDay(int thang,int nam){
        int _day = 30;
        int t = thang + 1;
        switch(t){
            case 1 : case 3 : case 5 : case 7 : case 8 : case 10:case 12:{
                _day = 31;
            }
            case 2:{
                if(nam %4 == 0 && nam %100!= 0 || nam%400 == 0){
                    _day = 29;
                }
                else{
                    _day = 28;
                }
                break;
            }
        }
        return _day;
    }
    String theo = "";
    private Boolean initdate(){
        Date d = new Date();
        int index_quy = this.cbbloai_baocao.getSelectedIndex();
        
        int _theoThang = this.cbbthang_quy.getSelectedIndex();
        if(_theoThang == 0 && index_quy < 2){
            if(index_quy == 0)
                JOptionPane.showMessageDialog(this, "Bạn chưa chọn tháng để báo cáo");
            else
                if(index_quy == 1)
                    JOptionPane.showMessageDialog(this, "Bạn chưa chọn qúy để báo cáo");
            return false;
        }
        int _nam = this.cbbnam.getSelectedIndex();
        int day = 1;
        int eday = 30;
        int ethang = d.getMonth();
        int thang = d.getMonth();
        int year = d.getYear();
        if(_nam == 0){
                JOptionPane.showMessageDialog(this, "Bạn chưa chọn năm để báo cáo");
                return false;
        }
        _nam = Integer.parseInt(this.cbbnam.getSelectedItem().toString());
        switch(index_quy){
            case 0:{
                theo = String.format("(Tháng %s Năm %s)", _theoThang,this.cbbnam.getSelectedItem().toString());
                thang = _theoThang - 1;
                ethang = _theoThang - 1;
                eday = this.getDay(ethang, _nam);
                break;
            }
            case 1:{
                theo = String.format("(Qúy %s - Năm %s)", _theoThang,this.cbbnam.getSelectedItem().toString());
                ethang = _theoThang * 3 - 1;
                thang = ethang - 2;
                eday = this.getDay(ethang, _nam);
                break;
            }
            case 2:{
                theo = String.format("(Năm %s)",this.cbbnam.getSelectedItem().toString());
                thang = 0;
                ethang = 11;
                eday = 31;
                break;
            }
        }        
        year = _nam - 1900;
        begin = new Timestamp(year, thang, day, 0, 0, 1, 0);
        end = new Timestamp(year, ethang, eday, 23, 59, 50, 0);  
        return true;
    }
    
    private void baoCaoTonKho(String title){
         int _thang = cbbthang_quy.getSelectedIndex();
        if(_thang == 0){
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn tháng để báo cáo");
            return;
        }
        int _nam = this.cbbnam.getSelectedIndex();
        if(_nam == 0){
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn năm để báo cáo");
            return;
        }
        _nam = Integer.parseInt(this.cbbnam.getSelectedItem().toString());
        CKho kho = new CKho();
        int indexkho = this.cbbkho.getSelectedIndex();
        if(indexkho >=0 && indexkho < this.lcuaHang.size()){
            kho = this.lcuaHang.get(indexkho);
        }
        String fileName = QuanLySieuThi.pathFolderReport + "tonkho.jrxml" ;        
        HashMap parameters = new HashMap();
        parameters.put("title", title);
        parameters.put("p_diachi", kho.getDiaChi());
        parameters.put("p_dienthoai", kho.getDienThoai());
        parameters.put("p_fax", kho.getFax());
        parameters.put("p_kho","(" + kho.getTenKho() +")");
        if(loai ==3){
            //p_titleslxuat_ban
            parameters.put("p_titleslxuat_ban", "SL Xuất");
        }
        else{
            parameters.put("p_titleslxuat_ban", "SL Bán");
        }
        CReport _report = new CReport();
        List<CTon_Kho> list = _report.getTonKho(kho.getId(),_thang, _nam);
        if(list.size() == 0){
            JOptionPane.showMessageDialog(this, String.format("Kho %s chưa có dữ liệu của tháng %s năm %s",
                    kho.getTenKho(),_thang,_nam));
            return;
        }
        JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(list);
        FrmReport f = null;// new FrmReport(begin, end, kho, loai_phieu, fileName, title,theo);
        f = new FrmReport(collectionDataSource, fileName, parameters);
        f.setVisible(true);
    }
    
    private void baoCaoToanHeThong(){
       Boolean flag = this.initdate();
       if(flag){
           String fileName = QuanLySieuThi.pathFolderReport + "bchethong.jrxml" ;//"baocaoloinhuan.jrxml";
           String title ="BÁO CÁO LỢI NHUẬN TOÀN HỆ THỐNG";
           String diachi = "Địa chỉ :" ;
           String dienthoai = "Điện thoại :" ;
           String fax = "Fax :" ;                
           List<CHeThong>list = new ArrayList<CHeThong>();
           String p_TitleTong = "";
           CReport _report = new CReport();
           String giamdoc ="";
           CConfig cf = null;
           if(QuanLySieuThi.cfParams != null){
               cf = (CConfig)QuanLySieuThi.cfParams.get("diachi");
               if(cf != null){
                   diachi = diachi + cf.getValue();
               }
               cf = (CConfig)QuanLySieuThi.cfParams.get("giamdoc");
               if(cf != null){
                   giamdoc =  cf.getValue();
               }
           }
           if(loai == 5){//doanh thu
               title ="BÁO CÁO DOANH THU TOÀN HỆ THỐNG";
               list = _report.getBaoDoanhThuHeThong(begin, end);
               p_TitleTong ="Doanh thu";
           }
           else{
               list = _report.getLoiNhuanHeThong(begin, end);
               p_TitleTong ="Lợi nhuận";
           }
           HashMap parameters = new HashMap();
           parameters.put("p_title", title);
           parameters.put("p_tong", p_TitleTong);
           parameters.put("p_diachi", diachi);
           parameters.put("p_giamdoc", giamdoc);
           parameters.put("p_titlegiamdoc","Giám đốc");
           JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(list);
           FrmReport f = null;// new FrmReport(begin, end, kho, loai_phieu, fileName, title,theo);
           f = new FrmReport(collectionDataSource, fileName, parameters);
           f.setVisible(true);
       }
    }
    
    private void baoCaoLoiNhuan() throws SQLException{
       Boolean flag = this.initdate();
       if(flag){
            String loai_phieu ="HDBH";
            String fileName = QuanLySieuThi.pathFolderReport + "baocaoloinhuan.jrxml" ;//"baocaoloinhuan.jrxml";
            String title ="BÁO CÁO LỢI NHUẬN";
            CKho kho = new CKho();
            kho.setId(2);
            int indexkho = this.cbbkho.getSelectedIndex();
            if(indexkho >=0 && indexkho < this.lcuaHang.size()){
                kho = this.lcuaHang.get(indexkho);
            }                
            List<CChiTietHoaDon> list = new ArrayList<CChiTietHoaDon>();
            if(kho == null){                
                return;
            }
                String diachi = "Địa chỉ :" + kho.getDiaChi();
                String dienthoai = "Điện thoại :" + kho.getDienThoai();
                String fax = "Fax :" + kho.getFax();                
                long kho_id = kho.getId();
                CReport _report = new CReport();
                list = _report.getChiTietHoaDon(this.begin, this.end, kho_id, "HDBH");
                HashMap parameters = new HashMap();
                parameters.put("title", title);
                parameters.put("p_diachi", diachi);
                parameters.put("p_dienthoai", dienthoai);
                parameters.put("fax", fax);//
                parameters.put("p_theo", this.theo);//"src/report/baocaoloinhuan.jrxml"
                JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(list);
                FrmReport f = null;// new FrmReport(begin, end, kho, loai_phieu, fileName, title,theo);
                f = new FrmReport(collectionDataSource, fileName, parameters);
                f.setVisible(true);
       }
    }
    
    private void baoCaoDoanhThu(){
        Boolean flag = this.initdate();
       if(flag){
            try {
                String loai_phieu ="HDBH";
                String fileName = QuanLySieuThi.pathFolderReport + "doanhthu.jrxml" ;//"baocaoloinhuan.jrxml";
                String title ="BÁO CÁO DOANH THU";
                CKho kho = new CKho();
                kho.setId(2);
                int indexkho = this.cbbkho.getSelectedIndex();
                if(indexkho >=0 && indexkho < this.lcuaHang.size()){
                    kho = this.lcuaHang.get(indexkho);
                }
                List<CChiTietHoaDon> list = new ArrayList<CChiTietHoaDon>();
                if(kho == null){
                    return;
                }
                String diachi = "Địa chỉ :" + kho.getDiaChi();
                String dienthoai = "Điện thoại :" + kho.getDienThoai();
                String fax = "Fax :" + kho.getFax();                
                long kho_id = kho.getId();
                CReport _report = new CReport();
                list = _report.getDoanhThuCuaHang(begin, end, kho_id);
                HashMap parameters = new HashMap();
                parameters.put("p_title", title);
                parameters.put("p_diachi", diachi);
                parameters.put("p_dienthoai", dienthoai);
                parameters.put("p_fax", fax);//
                parameters.put("p_theo", this.theo);//"src/report/baocaoloinhuan.jrxml"
                JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(list);
                FrmReport f = null;// new FrmReport(begin, end, kho, loai_phieu, fileName, title,theo);
                f = new FrmReport(collectionDataSource, fileName, parameters);
                f.setVisible(true);
            } catch (SQLException ex) {
                Logger.getLogger(FrmBaoCao.class.getName()).log(Level.SEVERE, null, ex);
            }
       }
    }
   
    
    private void btnPrintfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintfActionPerformed
        // TODO add your handling code here:
        switch(this.loai){
            case 1:{
            try {
                this.baoCaoLoiNhuan();
            } catch (SQLException ex) {
                Logger.getLogger(FrmBaoCao.class.getName()).log(Level.SEVERE, null, ex);
            }
                break;
            }
            case 2:{
                baoCaoDoanhThu();
                break;
            }
            case 3:{
                String title ="BÁO CÁO TỒN KHO";
                baoCaoTonKho(title);
                break;
            }
            case 4:{
                String title ="BÁO CÁO CỬA HÀNG";
                baoCaoTonKho(title);
                break;                
            }
            case 5: case 6:{
                this.baoCaoToanHeThong();
                break;
            }
        }
       
    }//GEN-LAST:event_btnPrintfActionPerformed

    private void cbbloai_baocaoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbloai_baocaoItemStateChanged
        // TODO add your handling code here:
        if(evt.getStateChange() == ItemEvent.SELECTED){
            int index = this.cbbloai_baocao.getSelectedIndex();
            switch(index){
                case 0:{//thang
                    cbbthang_quy.setVisible(true);
                      this.cbbthang_quy.removeAllItems();
                      this.cbbthang_quy.addItem(" --- Chọn tháng --- ");
                        for(int i = 1;i <= 12;i++){
                            this.cbbthang_quy.addItem("" + i);
                        }
                    break;
                }
                case 1:{//quy
                    cbbthang_quy.setVisible(true);
                      this.cbbthang_quy.removeAllItems();
                      this.cbbthang_quy.addItem(" --- Chọn qúy --- ");
                      for(int i = 1;i <= 4;i++){
                            this.cbbthang_quy.addItem("" + i);
                     }
                    break;
                }
                case 2:{//nam
                    cbbthang_quy.setVisible(false);
                    break;
                }
            }
        }
    }//GEN-LAST:event_cbbloai_baocaoItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmBaoCao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmBaoCao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmBaoCao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmBaoCao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmBaoCao().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnPrintf;
    private javax.swing.JComboBox cbbkho;
    private javax.swing.JComboBox cbbloai_baocao;
    private javax.swing.JComboBox cbbnam;
    private javax.swing.JComboBox cbbthang_quy;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JPanel pal1;
    private javax.swing.JPanel pan_cuahangkho;
    private javax.swing.JPanel pan_thang;
    // End of variables declaration//GEN-END:variables
}
